import React from 'react';
import moment from 'moment';
import Greeting from './greeting.js';

class Clock extends React.Component {
	constructor(props){
		super(props);
		this.state = {date: new Date()};
	}

	componentDidMount() {
	   this.timerID = setInterval(
	      () => this.tick(),
	      1000
	   );
	}

	componentWillUnmount() {
	   clearInterval(this.timerID);
	}

	moment(date) {
	    return moment(date).format('YYYY 年 MM 月 DD 日 HH:mm:ss');
	}


	tick() {
	  this.setState({
	  	date: new Date()
	  })
	}

	render() {
		return (
	      <div className="clock">
	        <span>{this.moment(this.state.date)}</span>
	      </div>
	    );
	}
}

export default Clock;